<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>login-sdk</title>
  <script src="http://srxboys.cn:8885/dist/rxcornor.js" id="rxcornor" link="https://gitee.com/cheere/rxlogin-sdk" target="_blank" title="Gitee"></script>
</head>

<body>
  <h2>login-sdk</h2>

  <div>
    <input name="check" id='check' type="checkbox" />
    同意协议
  </div>

  <div>
    <button type="submit" id="btn_submit" onclick="btnAction()">登录</button>
  </div>

  <script>
    function btnAction() {
      const search = location.search || ' '
      const query = search.substr(1)
      const vargs = query.split('&')
      const params = {}
      for (let i = 0; i < vargs.length; i++) {
        var pair = vargs[i].split('=')
        params[pair[0]] = pair[1] || ''
      }
      console.log('params=', params) // 跨域的话，这里还是行不通

      let win = null

      // https://developer.mozilla.org/zh-CN/docs/Web/API/Window/postMessage
      // postMessage - 第二个参数 -> targetOrigin:   https://a.com , * ，只能指定一个，或者所有
      if (window.opener) {
        if (!window.opener.closed) {
          window.opener.postMessage('result-【pc】-ok-this', '*')
          // or
          // window.opener.postMessage({a: 1, b: 2}, '*')
        }
        window.close()
      } else if (parent && parent.window) {
        parent.window.postMessage('result-[mobile]-ok-this', '*')
      }
    }
  </script>
</body>

</html>